package com.lch.sort;

/**
 * @author 刘晨辉
 * @date 2021/8/23 1:06 下午
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] a = new int[]{43, 5, 7, 3, 7, 3};

        for (int i = 1; i < a.length; i++) {
            int j = i - 1;
            int value = a[i];
            for (; j >= 0; --j) {
                if (value < a[j]) {
                    a[j + 1] = a[j];
                } else {
                    break;
                }
            }
            a[j + 1] = value;
        }

        for (int i = 0; i < a.length; i++) {
            System.out.printf(a[i] + ",");
        }
    }
}
